package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/redis")
public class RedisController {
    @Autowired
    private RedisTemplate redisTemplate;
    @GetMapping("get/{key}")
    public String get(@PathVariable("key")String key) {
        Object o = redisTemplate.opsForValue().get(key);
        return o == null ?"val is null":o.toString();
    }
    @GetMapping("set/{key}/{val}")
    public String set(@PathVariable("key")String key,@PathVariable("val")String val) {
        redisTemplate.opsForValue().set(key,val);
        return "OK";
    }
}
